package com.example.demo;

import com.example.demo.model.Emp;
import com.example.demo.reposition.EmpReposition;
import com.example.demo.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
@Slf4j
@EnableJpaRepositories
@EnableTransactionManagement
@EnableCaching(proxyTargetClass = true)
public class DemoApplication implements CommandLineRunner {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

	@Autowired
	EmpReposition empReposition;

	@Autowired
	EmpService empService;

	@Override
	public void run(String... args) throws Exception {
		log.info("out");
		Emp emp = Emp.builder().name("张三").job("主管")
				.salary(Money.of(CurrencyUnit.of("CNY"), 20.0)).build();

//		empReposition.save(emp);
//		empReposition.findAll().forEach(e->log.info(e.toString()));
		empService.findAllEmps().forEach(e->log.info(e.toString()));

		log.info("==================");
		empService.evict();
		empService.findAllEmps().forEach(e->log.info(e.toString()));

	}



}
